/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8                               :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2021 Justine Alexandra Roberts Tunney                              │
│                                                                              │
│ Permission to use, copy, modify, and/or distribute this software for         │
│ any purpose with or without fee is hereby granted, provided that the         │
│ above copyright notice and this permission notice appear in all copies.      │
│                                                                              │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             │
│ PERFORMANCE OF THIS SOFTWARE.                                                │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/struct/rlimit.h"
#include "libc/fmt/itoa.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/intrin/describeflags.h"

/**
 * Describes setrlimit() / getrlimit() argument.
 */
const char *_DescribeRlimitName(char buf[20], int resource) {
  switch (resource) {
    case RLIMIT_CPU:
      return "RLIMIT_CPU";
    case RLIMIT_FSIZE:
      return "RLIMIT_FSIZE";
    case RLIMIT_DATA:
      return "RLIMIT_DATA";
    case RLIMIT_STACK:
      return "RLIMIT_STACK";
    case RLIMIT_CORE:
      return "RLIMIT_CORE";
    case RLIMIT_RSS:
      return "RLIMIT_RSS";
    case RLIMIT_NPROC:
      return "RLIMIT_NPROC";
    case RLIMIT_NOFILE:
      return "RLIMIT_NOFILE";
    case RLIMIT_MEMLOCK:
      return "RLIMIT_MEMLOCK";
    case RLIMIT_AS:
      return "RLIMIT_AS";
    default:
      FormatInt32(buf, resource);
      return buf;
  }
}
